# _*_ coding : utf-8 _*_
# @Time : 2023/3/15 0015 10:29
# @Author : 菜鸟王小二
# @File : 9_urllib_ajax的get请求豆瓣电影
# @Project : python爬虫

import urllib.request
import urllib.parse

url = 'https://movie.douban.com/j/search_subjects?'
data = {
    'type':'movie',
    'tag':'最新',
    'page_limit':'50',
    'page_start':'0'
}
url = url + urllib.parse.urlencode(data)
print(url)
headers = {
    'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63'
}

request = urllib.request.Request(url=url,headers=headers)
response = urllib.request.urlopen(request)
text = response.read().decode('utf-8')
print(text)

with open('newMovie.json','w',encoding='utf-8') as fp:
    fp.write(text)
